<template>
    <el-dialog :title="type=='1'?'新增出院申请':'编辑出院申请'" visible @close="$emit('close')" width="400px" append-to-body :close-on-click-modal="false">
        <el-form ref="form" :model="form" :rules="rules" label-width="100px" v-loading="lodaing">
            <el-col :span="24">
                <el-form-item label="老人" prop="name">
                    <span>{{name}}</span>
                </el-form-item>
            </el-col>
            <el-col :span="24">
                <el-form-item label="预计时间" prop="due_time">
                    <el-date-picker v-model="form.due_time" type="date" value-format="yyyy-MM-dd" placeholder="请选择预计时间" />
                </el-form-item>
            </el-col>
            <el-col :span="24">
                <el-form-item label="出院原因" prop="reason">
                    <el-input v-model="form.reason" type="textarea" rows="2" placeholder="请输入出院原因"></el-input>
                </el-form-item>
            </el-col>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button @click="$emit('close')">取 消</el-button>
            <el-button type="primary" @click="submit" :disabled="lodaing">确 定</el-button>
        </span>
    </el-dialog>
</template>

<script>
import throttle from 'lodash.throttle'
import { setHospToLeaveApply } from "@/api/marketing/admit"
export default {
    name: '',
    props: {
        type: Number, //1新增2編輯
        customerId: Number,
        name: {
            type: String,
            default: ""
        }
    },
    data() {
        return {
            lodaing: false,
            form: {
                customer_id: this.customerId,
                reason: null,
            },
            rules: {
                reason: [{ required: true, message: '请输入出院原因', trigger: 'blur' }],
                due_time: [{ required: true, message: '请选择开始时间', trigger: 'blur' }],
            },
        }
    },
    created() {
        
    },
    methods: {
        submit: throttle(function () {
            this.$refs.form.validate((valid) => {
                if (valid) {
                    this.lodaing = true;
                    setHospToLeaveApply(this.form).then(res => {
                        this.msgSuccess("操作成功！");
                        this.$emit('close')
                        this.lodaing = false;
                        this.$emit('load')
                    }).catch(() => {
                        this.lodaing = false;
                    })
                }
            })
        }, 1000, { trailing: false }),
    }
}
</script>

<style lang='scss' scoped>
</style>
